package com.atguigu.controller;


import com.atguigu.entity.PlatformPropertyKey;
import com.atguigu.entity.PlatformPropertyValue;
import com.atguigu.result.RetVal;
import com.atguigu.service.PlatformPropertyKeyService;
import com.atguigu.service.PlatformPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性表 前端控制器
 * </p>
 *
 * @author yangchaolove
 * @since 2021-11-07
 *
 */
@RestController
@RequestMapping("/product")
//@CrossOrigin
public class PlatformPropertyController {

    @Autowired
    private PlatformPropertyKeyService  propertyKeyService;
    @Autowired
    private PlatformPropertyValueService propertyValueService;


    @GetMapping("/getPlatformPropertyByCategoryId/{category1Id}/{category2Id}/{category3Id}")
    public RetVal getPlatformPropertyByCategoryId(
            @PathVariable Long category1Id,
            @PathVariable Long category2Id,
            @PathVariable Long category3Id){
        List<PlatformPropertyKey> platformPropertyList=propertyKeyService.getPlatformPropertyByCategoryId(category1Id,category2Id,category3Id);
        return RetVal.ok(platformPropertyList);
    }

    //根据平台属性key获取vlaue
    @GetMapping("/getPropertyValueByPropertyKeyId/{propertyKeyId}")
    public RetVal getPropertyValueByPropertyKeyId( @PathVariable Long propertyKeyId){
        List<PlatformPropertyValue> list = propertyValueService.getPropertyValueByPropertyKeyId(propertyKeyId);
        return RetVal.ok(list);
    }
    //修改 新增(保存)
    @PostMapping("/savePlatformProperty")
    public RetVal savePlatformProperty(@RequestBody PlatformPropertyKey platformPropertyKey){
        propertyKeyService.savePlatformProperty(platformPropertyKey);
        return RetVal.ok();
    }

    //删除
    @DeleteMapping("/deletePlatformProperty/{id}")
    public RetVal deletePlatformProperty(@PathVariable("id") Long id){
        propertyKeyService.deletePlatformProperty(id);
        return RetVal.ok();
    }
    //4.根据skuId查询平台属性信息
    @GetMapping("getPlatformPropertyBySkuId/{skuId}")
    public List<PlatformPropertyKey> getPlatformPropertyBySkuId(@PathVariable Long skuId){
        return propertyKeyService.getPlatformPropertyBySkuId(skuId);
    }





}

